﻿#region Usings
using System;
using BK.BL;
using BK.Entities;
using BK.WebSite.AppCode;
#endregion

namespace BK.WebSite.Controls
{
	public partial class PaymentEditControl : BkDataEditControl<PaymentEntity, Payments>
	{
		#region Instance Methods
		protected override void DoGetObjectFromEditor(PaymentEntity entity)
		{
			entity.AccountId.Assign(hfAcountId.Text);
			entity.CategoryId.Assign(hfCategoryId.Value);
			entity.Amount = decimal.Parse(tbxAmount.Text);
			entity.Description = tbxDescription.Text;
			entity.DateTime = DateTime.Parse(tbxDate.Text + " " + tbxTime.Text);
			entity.UserId.Assign(UserProvider.GetCurrentUser().Id);
		}

		protected override void DoPutObjectToEditor(PaymentEntity entity)
		{
			tbxDate.Text = entity.DateTime.Date.ToShortTimeString();
			tbxTime.Text = entity.DateTime.TimeOfDay.ToString();
			tbxAmount.Text = entity.Amount.ToString();
			tbxDescription.Text = entity.Description;
			tbxDate.Text = entity.DateTime.Date.ToShortDateString();
			tbxTime.Text = entity.DateTime.Date.ToShortTimeString();
			
			tbxAccounts.Text = BlContext.Instance.Accounts.Load(entity.AccountId).Name;
			hfAcountId.Text = entity.AccountId.ToString();

			tbxCategory.Text = BlContext.Instance.Categories.Load(entity.CategoryId).FullName;
			hfCategoryId.Value = entity.CategoryId.ToString();
		}

		protected override void PrepareEditor()
		{
			DateTime now = DateTime.Now;
			tbxDate.Text = now.ToShortDateString();
			tbxTime.Text = now.ToShortTimeString();
		}

		protected void Page_Load(object sender, EventArgs e)
		{
		}
		#endregion
	}
}